﻿using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Activities;
using System.Activities.Runtime;
using System.DirectoryServices;

namespace Vision.Core.ActivityComponents.ActiveDirectory
{
    /// <summary>
    /// 
    /// </summary>
    public class GetGroupByAlias : CodeActivity
    {
        /// <summary>
        /// 
        /// </summary>
        [DefaultValue(null)]
        public InArgument<string> GroupName { get; set; }

        /// <summary>
        /// The resultant DirectoryEntry.
        /// </summary>
        [DefaultValue(null)]
        public OutArgument<DirectoryEntry> Entry { get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="context"></param>
        protected override void Execute(CodeActivityContext context)
        {            
            if (!string.IsNullOrEmpty(context.GetValue(this.GroupName))){
                string filter = "(&(objectClass=Group)(sAMAccountName=" + context.GetValue(this.GroupName) + "))";
                DirectoryEntry directoryEntry = ActiveDirectoryHelper.GetDirectoryEntry(filter);
                context.SetValue(this.Entry, directoryEntry);
            }
        }
    }
}
